home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / hydrabbsa8 / source / src.lha / utils / hbbsmutlitop / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  11.0 KB  |  523 lines

  1. /* **** HBBS Door Code****************************************************** */
  2.  
  3. /*
  4.   DoorName
  5.   ========
  6.  
  7.     HBBSMultiTop
  8.  
  9.   Version
  10.   =======
  11.  
  12.     1.0, release  1, 26/12/1995
  13.  
  14.   Options
  15.   =======
  16.  
  17.     N_ND->ActiveDoor->SystemOptions
  18.     -------------------------------
  19.  
  20.  
  21.  
  22.     Command Line Arguments
  23.     ----------------------
  24.  
  25.   ToDo
  26.   ====
  27.  
  28.  
  29.  
  30.  
  31. */
  32.  
  33. /* **** Includes *********************************************************** */
  34.  
  35. #include <exec/types.h>
  36. #include <exec/memory.h>
  37. #include <dos/dos.h>
  38. #include <clib/exec_protos.h>
  39. #include <clib/dos_protos.h>
  40. #include <clib/alib_protos.h>
  41.  
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <stdio.h>
  45. #include <ctype.h>
  46. #include <time.h>
  47.  
  48. #include <HBBS/ANSI_Codes.h>
  49. #include <HBBS/Defines.h>
  50. #include <HBBS/types.h>
  51. #include <HBBS/Access.h>
  52. #include <HBBS/structures.h>
  53. #include <HBBS/hbbscommon_protos.h>
  54. #include <HBBS/hbbscommon_pragmas.h>
  55. #include <HBBS/Hbbsnode_protos.h>
  56. #include <HBBS/Hbbsnode_pragmas.h>
  57.  
  58. /* **** Definitions ******************************************************** */
  59.  
  60. #define BENS_HEADER "+------------------------------------------------------+\r\n|            Zippy Search V1 by Ben Clifton            |\r\n|           (C) 1995 Ruby Knight Productions           |\r\n+------------------------------------------------------+\r\n"
  61.  
  62. /* **** Variables ********************************************************** */
  63.  
  64.  
  65. struct Library *HBBSCommonBase  = NULL;
  66. struct Library *HBBSNodeBase    = NULL;
  67.  
  68. struct BBSGlobalData *BBSGlobal = NULL;
  69. struct NodeData *N_ND           = NULL;
  70. int    N_NodeNum                = -1;
  71.  
  72. long __stack=16*1024; // increse this in 4k incrments if you suffer from
  73.                       // random/suprious crashings after or during the running
  74.                       // of your door.
  75.  
  76. int    gargc;         // these are just copies of main()'s argc and argv..
  77. char   **gargv;
  78.  
  79. ULONG CurrentFileNumber = 0;
  80. ULONG LinesOutput = 0;
  81.  
  82. BOOL GBL_Error = FALSE;
  83.  
  84. struct List *UserNames;
  85. struct List *ULFiles;
  86. struct List *ULBytes;
  87. struct List *DLFiles;
  88. struct List *DLBytes;
  89.  
  90. char tmpstr[BIG_STR];
  91.  
  92. /* **** Functions ********************************************************** */
  93.  
  94.  
  95. #ifdef __SASC
  96. int CXBRK(void) { return(0); }
  97. int _CXBRK(void) { return(0); }
  98. void chkabort(void) {}
  99. #endif
  100.  
  101. static VOID cleanup(ULONG num)
  102. {
  103.   if (HBBSCommonBase)
  104.   {
  105.     HBBS_CleanUpCommon();
  106.     CloseLibrary (HBBSCommonBase);
  107.   }
  108.  
  109.   if (num) printf("Door Error = %d\n",num);
  110.  
  111.   exit(0);
  112. }
  113.  
  114. static VOID init( void )
  115. {
  116.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  117.   {
  118.     cleanup(1);
  119.   }
  120.  
  121.   if (!(HBBS_InitCommon()))
  122.   {
  123.     cleanup(2);
  124.   }
  125. }
  126.  
  127. void FM_strFNcpy( char *in, char *out, int start, int num )
  128. {
  129.   int loop, i;
  130.  
  131.   for( i=0, loop = start; (loop < num+start) && (in[loop]); loop++, i++ ) out[i] = in[loop];
  132.   out[i]=0;
  133. }
  134.  
  135. void FM_RemoveCR( char *s )
  136. {
  137.   if( s[0] )
  138.   {
  139.     if( (s[strlen(s)-1] == '\n')|| (s[strlen(s)-1] == '\r' ) )
  140.       s[strlen(s)-1] = 0;
  141.     if( (s[strlen(s)-1] == '\n')|| (s[strlen(s)-1] == '\r' ) )
  142.       s[strlen(s)-1] = 0;
  143.   }
  144. }
  145.  
  146. void strpad(char *buffer, int requiredlen, UBYTE PadChar)
  147. {
  148.   int many;
  149.   int loop;
  150.   int clen=strlen(buffer);
  151.  
  152.   if (clen<requiredlen)
  153.   {
  154.     many=requiredlen-clen;
  155.     for (loop=0;loop<=many;loop++) buffer[clen+loop]=PadChar;
  156.     buffer[requiredlen]=0;
  157.   }
  158. }
  159.  
  160. struct List *ReadTextFile( char *filename )
  161. {
  162.   return( HBBS_LoadFile( filename ));
  163. }
  164.  
  165. //  tmpstr="my mother was a boar"
  166.  
  167. //  replace(tmpstr,tmpstr,"boar","whoar");
  168.  
  169. #define SORT_UPLOADEDBYTES     0
  170. #define SORT_UPLOADEDFILES     1
  171. #define SORT_DOWNLOADEDBYTES   2
  172. #define SORT_DOWNLOADEDFILES   3
  173. #define SORT_CALLS             4
  174. #define SORT_MESSAGES          5
  175.  
  176. void CheckForConfigs( struct List *data )
  177. {
  178.   short where;
  179.  
  180.   for( ptr = data->lh_Head; ptr->ln_Succ; ptr = ptr->ln_Succ )
  181.   {
  182.     if( iposition( "SORT=", ptr->ln_Name ) >= 0 )
  183.     {
  184.       if( iposition( "UPLOADEDBYTES", ptr->ln_Name ) >= 0 )
  185.       {
  186.         SortBy = SORT_UPLOADEDBYTES;
  187.       }
  188.       else
  189.       if( iposition( "UPLOADEDFILES", ptr->ln_Name ) >= 0 )
  190.       {
  191.         SortBy = SORT_UPLOADEDFILES;
  192.       }
  193.       else
  194.       if( iposition( "DOWNLOADEDBYTES", ptr->ln_Name ) >= 0 )
  195.       {
  196.         SortBy = SORT_DOWNLOADEDBYTES;
  197.       }
  198.       else
  199.       if( iposition( "DOWNLOADEDFILES", ptr->ln_Name ) >= 0 )
  200.       {
  201.         SortBy = SORT_DOWNLOADEDFILES;
  202.       }
  203.       else
  204.       if( iposition( "CALLS", ptr->ln_Name ) >= 0 )
  205.       {
  206.         SortBy = SORT_CALLS;
  207.       }
  208.       else
  209.       if( iposition( "MESSAGES", ptr->ln_Name ) >= 0 )
  210.       {
  211.         SortBy = SORT_MESSAGES;
  212.       }
  213.       /* Do not display this line so remove it from the list! */
  214.       FreeStr(ptr->ln_Name);
  215.       Remove(ptr);
  216.       FreeVec(ptr);
  217.     }
  218.   }
  219. }
  220.  
  221. #define KEY_UB 0
  222. #define KEY_UK 1
  223. #define KEY_UM 2
  224. #define KEY_UF 3
  225. #define KEY_DB 4
  226. #define KEY_DK 5
  227. #define KEY_DM 6
  228. #define KEY_DF 7
  229. #define KEY_UN 8
  230. #define KEY_CS 9
  231. #define KEY_MS 10
  232. #define KEY_DF 11
  233. #define KEY_LT 12
  234. #define KEY_ST 13
  235.  
  236. int ConvertKeyword( char *keyword )
  237. {
  238.   if( stricmp( "UB", keyword ) )
  239.     return( KEY_UB );
  240.   else
  241.   if( stricmp( "UK", keyword ) )
  242.     return( KEY_UK );
  243.   else
  244.   if( stricmp( "UM", keyword ) )
  245.     return( KEY_UM );
  246.   else
  247.   if( stricmp( "UF", keyword ) )
  248.     return( KEY_UF );
  249.   else
  250.   if( stricmp( "DB", keyword ) )
  251.     return( KEY_DB );
  252.   else
  253.   if( stricmp( "DK", keyword ) )
  254.     return( KEY_DK );
  255.   else
  256.   if( stricmp( "DM", keyword ) )
  257.     return( KEY_DM );
  258.   else
  259.   if( stricmp( "DF", keyword ) )
  260.     return( KEY_DF );
  261.   else
  262.   if( stricmp( "UN", keyword ) )
  263.     return( KEY_UN );
  264.   else
  265.   if( stricmp( "CS", keyword ) )
  266.     return( KEY_CS );
  267.   else
  268.   if( stricmp( "MS", keyword ) )
  269.     return( KEY_MS );
  270.   else
  271.   if( stricmp( "DF", keyword ) )
  272.     return( KEY_DF );
  273.   else
  274.   if( stricmp( "LT", keyword ) )
  275.     return( KEY_LT );
  276.   else
  277.   if( stricmp( "ST", keyword ) )
  278.     return( KEY_ST );
  279. }
  280.  
  281. void DoReplacement( string, pos, length, centre, char *type )
  282. {
  283.   char replacement[BIG_STR], char *newstring;
  284.  
  285.   switch( ConvertKeyword( type )
  286.   {
  287.     case KEY_UB:
  288.       break;
  289.     case KEY_UK:
  290.       break;
  291.     case KEY_UM:
  292.       break;
  293.     case KEY_UF:
  294.       break;
  295.     case KEY_DB:
  296.       break;
  297.     case KEY_DK:
  298.       break;
  299.     case KEY_DM:
  300.       break;
  301.     case KEY_DF:
  302.       break;
  303.     case KEY_UN:
  304.       break;
  305.     case KEY_CS:
  306.       break;
  307.     case KEY_MS:
  308.       break;
  309.     case KEY_DF:
  310.       break;
  311.     case KEY_LT:
  312.       break;
  313.     case KEY_ST:
  314.       strcpy( replacement, "This is a test!" );
  315.       if( newstring = AllocVec( BIG_STR, MEMF_PUBLIC|MEMF_CLEAR ) )
  316.       {
  317.         replace(newstring, string, actualcommand, replacement);
  318.         ptr->ln_Name = newstring;
  319.         FreeVec( string );
  320.       }
  321.       break;
  322.   }
  323. }
  324.  
  325. LONG CreateOutput( struct List *data, struct List *outdata )
  326. {
  327.   struct Node *ptr;
  328.   char *FieldStart, *fptr;
  329.   BOOL Exit;
  330.   char KeyWorkType[5];
  331.   char tmp[5];
  332.   int pos, length, centre = JUST_RIGHT, num;
  333.  
  334.   for( ptr = data->lh_Head; ptr->ln_Succ; ptr = ptr->ln_Succ )
  335.   {
  336.     fptr = ptr->ln_Name;
  337.     while( FieldStart = FindKeywordStart( fptr ) )
  338.     {
  339.       //             User No. -=left .centre
  340.       // Command "%<pos><center><length><keyword> Example %01-10UN
  341.  
  342.       Exit = FALSE;
  343.       for( i=1; (i<7)&&(!Exit); i++ )
  344.       {
  345.         if( (FieldStart[i] > 'A') && (FieldStart[i] < 'Z')
  346.         {
  347.           Exit = TRUE;
  348.         }
  349.       }
  350.  
  351.       // %nncnncc  6
  352.       // %cnncc    4
  353.       // %cc       1
  354.       // %nncc     3
  355.  
  356.       if( i <= 6 )
  357.       {
  358.         KeyWorkType[0] = FieldStart[i];
  359.         KeyWorkType[1] = FieldStart[i+1];
  360.         KeyWorkType[2] = 0;
  361.  
  362.  
  363.         if( i > 1 )
  364.         {
  365.           if( i == 3 )
  366.           {
  367.             tmp[0] = FieldStart[1];
  368.             tmp[1] = FieldStart[2];
  369.             tmp[2] = 0;
  370.             pos = atoi( tmp );
  371.           }
  372.           else
  373.           {
  374.             if( i==4 )
  375.             {
  376.               num = 1;
  377.             }
  378.             else
  379.             {
  380.               num = 3;
  381.             }
  382.  
  383.             switch( FieldStart[num] )
  384.             {
  385.               case '-':
  386.                 centre = JUST_LEFT;
  387.                 break;
  388.               case '.':
  389.                 centre = JUST_CENTRE;
  390.                 break;
  391.               default:
  392.                 centre = JUST_RIGHT;
  393.                 break;
  394.             }
  395.             tmp[0] = FieldStart[num+1];
  396.             tmp[1] = FieldStart[num+2];
  397.             tmp[2] = 0;
  398.             length = atoi( tmp );
  399.             if( num > 2 )
  400.             {
  401.               tmp[0] = FieldStart[1];
  402.               tmp[1] = FieldStart[2];
  403.               tmp[2] = 0;
  404.               pos = atoi( tmp );
  405.             }
  406.           }
  407.         }
  408.  
  409.         if( (FieldStart[1] > '0') && (FieldStart[1] > '9') && (FieldStart[2] > '0') && (FieldStart[2] > '9'))
  410.         {
  411.           tmp[0] = FieldStart[1];
  412.           tmp[1] = FieldStart[2];
  413.           tmp[2] = 0;
  414.           pos = atoi( tmp );
  415.         }
  416.         switch( FieldStart[3] )
  417.         {
  418.           case '.':
  419.           case '-':
  420.             if( i
  421.             break;
  422.         }
  423.  
  424.         DoReplacement( ptr->ln_Name, pos, length, centre, KeyWorkType );
  425.       }
  426.     }
  427.   }
  428. }
  429.  
  430. void SaveData( char *filename, struct List *data )
  431. {
  432.   HBBS_SaveFile( filename, data );
  433. }
  434.  
  435. /* **** UtilMain *********************************************************** */
  436.  
  437. void UtilMain( void )
  438. {
  439.   char outfilename[BIG_STR], infilename[BIG_STR];
  440.   LONG ConfNum;
  441.   LONG UserFlags;
  442.   struct List *inputfiledata;
  443.  
  444.   if( gargc < 2 )
  445.   {
  446.     Printf( "Teppic HBBSTopStat V1.0 by Ben Clifton\n"
  447.             "   (C)1995 Ruby Knight Productions\n"
  448.             "--------------------------------------\n"
  449.           );
  450.   }
  451.   else
  452.   {
  453.     switch( gargv[1][0] )
  454.     {
  455.       case '?':
  456.         Printf("\n"
  457.                "Usage : HBBSTopStat <design> <output> [<confnum>]\n"
  458.                "\n"
  459.                "  design  - Full path to your design file.\n"
  460.                "  output  - Full path to your output file.\n"
  461. //               "  sortby  - Field by which to sort UserList\n"
  462. //               "             UF Top File Uploaders (default)\n"
  463. //               "             UB Top Bytes Uploaders\n"
  464. //               "             DL Top File Downloaders\n"
  465. //               "             DB Top Bytes Downloaders\n"
  466.                "  confnum - Conference Number for data to be pulled from.\n"
  467.               );
  468.         break;
  469.       default:
  470.         strcpy( infilename, gargv[1] );
  471.  
  472.         if( gargc < 3 )
  473.         {
  474.           outfilename[0] = 0;
  475.         }
  476.         else
  477.         {
  478.           strcpy( outfilename, gargv[2] );
  479.         }
  480.  
  481.         if( gargc < 4 )
  482.         {
  483.           ConfNum = 1L;
  484.         }
  485.         else
  486.         {
  487.           ConfNum = atol( gargv[3] );
  488.         }
  489.  
  490.  
  491.         inputfiledata = ReadTextFile( infilename );
  492.         if( !GBL_Error )
  493.         {
  494.           CheckForConfigs( inputfiledata );
  495.           CreateDataLists( UserFlags );
  496.           if( !GBL_Error )
  497.           {
  498.             outputfiledata = CreateOutput( inputfiledata );
  499.             if( !GBL_Error )
  500.             {
  501.               SaveData( outfilename, outputfiledata );
  502.             }
  503.           }
  504.         }
  505.         break;
  506.     }
  507.   }
  508. }
  509.  
  510. int main(int argc,char **argv)
  511. {
  512.   gargc=argc;
  513.   gargv=argv;
  514.  
  515.   init();
  516.  
  517.   UtilMain();
  518.  
  519.   cleanup(0);
  520. }
  521.  
  522. /* **** End Of File ******************************************************** */
  523.